package com.itheima.sfbx.insurance.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.insurance.dto.CoefficentVO;
import com.itheima.sfbx.insurance.service.ICoefficentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* @author wangyoucheng
* @date 2025/9/18
* @description TOD0
*/
@RestController
@Api("系数项")
@RequestMapping("/coefficent")
public class CoefficentController {

    @Autowired
    private ICoefficentService coefficentService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页",notes = "分页")
    @ApiImplicitParams( {
            @ApiImplicitParam(name = "coefficentVo",value = "Vo对象",required = true,dataType = "CoefficentVO"),
            @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
            @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    @ApiOperationSupport(includeParameters = {"coefficentVo.sortNo","coefficentVo.coefficentKey","coefficentVo.coefficentName"})
    public ResponseResult<Page<CoefficentVO>> findCoefficentVOPage(
            @RequestBody CoefficentVO coefficentVO,
            @PathVariable("pageNum") int pageNum,
            @PathVariable("pageSize") int pageSize
    ){
        Page<CoefficentVO> coefficentVOPage = coefficentService.findPage(coefficentVO, pageNum, pageSize);
        return ResponseResultBuild.successBuild(coefficentVOPage);
    }

    @PutMapping
    @ApiOperation(value = "保存Coefficent",notes = "添加Cofficent")
    @ApiImplicitParam(name = "coefficentVO",value = "系数项VO对象",required = true,dataType = "CoefficentVO")
    @ApiOperationSupport(includeParameters = {"coefficentVO.dataState","coefficentVO.coefficentKey","coefficentVO.coefficentName","coefficentVO.sortNo"})
    public ResponseResult<CoefficentVO> createCoefficent(@RequestBody CoefficentVO coefficentVO){
        CoefficentVO coefficentVOResult = coefficentService.save(coefficentVO);
        return ResponseResultBuild.successBuild(coefficentVOResult);
    }

    @PatchMapping
    @ApiOperation(value = "修改系数项",notes = "修改系数项")
    @ApiImplicitParam(name = "coefficentVO",value = "系数项VO对象",required = true,dataType = "CoefficentVO")
    @ApiOperationSupport(includeParameters = {"coefficentVO.id","coefficentVO.dataState","coefficentVO.coefficentKey","coefficentVO.coefficentName","coefficentVO.sortNo"})
    public ResponseResult<Boolean> updateCoefficent(@RequestBody CoefficentVO coefficentVO){
        Boolean flag = coefficentService.update(coefficentVO);
        return ResponseResultBuild.successBuild(flag);
    }

    @DeleteMapping
    @ApiOperation(value = "删除系数项",notes = "删除系数项")
    @ApiImplicitParam(name = "coefficentVO",value = "系数项VO对象",required = true,dataType = "CoefficentVO")
    @ApiOperationSupport(includeParameters = {"coefficentVO.checkedIds"})
    public ResponseResult<Boolean> deleteCoefficent(@RequestBody CoefficentVO coefficentVO){
        Boolean flag = coefficentService.delete(coefficentVO.getCheckedIds());
        return ResponseResultBuild.successBuild(flag);
    }
    @PostMapping("list")
    @ApiOperation(value = "多条件查询系数项列表",notes = "多条件查询系数项列表")
    @ApiImplicitParam(name = "coefficentVO",value = "系数项VO对象",required = true,dataType = "CoefficentVO")
    @ApiOperationSupport(includeParameters = {"coefficentVO.dataState","coefficentVO.coefficentKey","coefficentVO.coefficentName","coefficentVO.sortNo"})
    public ResponseResult<List<CoefficentVO>> findCoefficentList(@RequestBody CoefficentVO coefficentVO){
        List<CoefficentVO> coefficentVOList = coefficentService.findList(coefficentVO);
        return ResponseResultBuild.successBuild(coefficentVOList);
    }











}
